home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Marathon Map Viewer / @Source / myApplication.cpp < prev    next >
C/C++ Source or Header  |  1995-06-06  |  5KB  |  168 lines

  1. /*-----------------------------------------------------------------
  2.     Copyright ©1994 Steve Israelson
  3.     
  4.     This file contains the source code for the function main(),
  5.     and the source for all the methods in the "myApplication"
  6.     class.  This class handles application specific stuff, like
  7.     creating new documents.
  8. -----------------------------------------------------------------*/
  9.  
  10. #include "myApplication.h"
  11. #include "myDocument.h"
  12. #include "myRegisterClasses.h"
  13. #include "commandNumbers.h"
  14.  
  15. myApplication        *theApp;    // our one global variable
  16.  
  17. /*-----------------------------------------------------------------
  18.     Main entry point.
  19. -----------------------------------------------------------------*/
  20. void main(void)
  21.     {
  22.                                     // Set Debugging options
  23.     InitializeHeap(15);                // Initialize Memory Manager
  24.                                     // Parameter is number of Master Pointer
  25.                                     //   blocks to allocate
  26.     
  27.                                     // Initialize standard Toolbox managers
  28.     UQDGlobals::InitializeToolbox(&qd);
  29.     
  30.     new LGrowZone(200000);            // Install a GrowZone function to catch
  31.                                     //    low memory situations.
  32.                                     //    Parameter is size of reserve memory
  33.                                     //    block to allocated. The first time
  34.                                     //    the GrowZone function is called,
  35.                                     //    there will be at least this much
  36.                                     //    memory left (so you'll have enough
  37.                                     //    memory to alert the user or finish
  38.                                     //    what you are doing).
  39.     
  40.     // some debugging settings
  41.     gDebugThrow = debugAction_SourceDebugger;
  42.     gDebugSignal = debugAction_SourceDebugger;
  43.  
  44.  
  45.     // create an instance of the application class and
  46.     // assign it to our global variable
  47.     theApp = new myApplication;
  48.     theApp->Run();                // run the application
  49.     delete theApp;                // by this point the application has quit, so get rid of it
  50.     }
  51.  
  52. /*-----------------------------------------------------------------
  53.     Construct a new editor application.
  54.     Registers some classes with powerplant and sets up the grow zone
  55.     to detect low memory conditions.
  56. -----------------------------------------------------------------*/
  57. myApplication::myApplication()
  58.     {
  59.         // Register classes for objects created from 'PPob' resources
  60.     RegisterAllPPClasses();
  61.     registerMyClasses();
  62.     
  63.     LGrowZone::GetGrowZone()->StartIdling();    // start the grow zone idling
  64.     }
  65.  
  66. /*-----------------------------------------------------------------
  67.     Cleans up when the application object is destroyed.
  68. -----------------------------------------------------------------*/
  69. myApplication::~myApplication()
  70.     {
  71.     }
  72.  
  73. /*-----------------------------------------------------------------
  74.     When the user clicks in the menu bar, this is called to see
  75.     how the menu should be drawn.  In our case, we do not want
  76.     the user opening new documents when memory is getting scarce.
  77. -----------------------------------------------------------------*/
  78. void myApplication::FindCommandStatus(
  79.         CommandT    inCommand,
  80.         Boolean        &outEnabled,
  81.         Boolean        &outUsesMark,
  82.         Char16        &outMark,
  83.         Str255        outName)
  84.     {
  85.     outUsesMark = false;
  86.     
  87.     switch (inCommand) 
  88.         {
  89.         case cmd_Open:    // do not allow the opening of more docs when mem is low.
  90.             if (LGrowZone::GetGrowZone()->MemoryIsLow())
  91.                 outEnabled = false;
  92.             else
  93.                 outEnabled = true;
  94.             break;
  95.         // +++ Add cases here for the commands you handle
  96.     
  97.         case cmd_Nothing:
  98.         default:
  99.             LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  100.                                 outMark, outName);
  101.             break;
  102.         }
  103.     }
  104.  
  105. /*-----------------------------------------------------------------
  106.     Actually handle the menu command.  When we define our own menu
  107.     commands, like show/hide the tool palette, we will actually
  108.     do something here.  For now let the class we inherit from handle
  109.     everything.
  110. -----------------------------------------------------------------*/
  111. Boolean myApplication::ObeyCommand(CommandT inCommand, void *ioParam)
  112.     {
  113.     Boolean        cmdHandled = true;
  114.     
  115.     switch (inCommand) 
  116.         {
  117.         case cmd_Nothing:
  118.         default:
  119.             cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  120.             break;
  121.         }
  122.     
  123.     return cmdHandled;
  124.     }
  125.  
  126. /*-----------------------------------------------------------------
  127.     Open a new document.  We do this by creating a new instance
  128.     of the "myDocument" class.
  129. -----------------------------------------------------------------*/
  130. void myApplication::OpenDocument(FSSpec *inMacFSSpec)
  131.     {
  132.     new myDocument(this, inMacFSSpec);
  133.     }
  134.  
  135. /*-----------------------------------------------------------------
  136.     Create a new document from scratch.  Note that it is not passed
  137.     a file name when the document is created.
  138. -----------------------------------------------------------------*/
  139. LModelObject *myApplication::MakeNewDocument()
  140.     {
  141.     return new myDocument(this, nil);
  142.     }
  143.  
  144. /*-----------------------------------------------------------------
  145.     Allow the user to choose documents.
  146.     Puts up a standard file dialog and lets the user choose only
  147.     our file types (maps).  Opens a document based on the file selected.
  148. -----------------------------------------------------------------*/
  149. void myApplication::ChooseDocument()
  150.     {
  151.     StandardFileReply    macFileReply;
  152.     SFTypeList            typeList;
  153.     
  154.     UDesktop::Deactivate();
  155.     typeList[0] = editorFileType;
  156.     ::StandardGetFile(nil, 1, typeList, &macFileReply);
  157.     UDesktop::Activate();
  158.     if (macFileReply.sfGood) 
  159.         {
  160.         OpenDocument(&macFileReply.sfFile);
  161.         }
  162.     }
  163.  
  164.  
  165.  
  166.  
  167.  
  168.